package Frame.dialog;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import controller.Controller;

import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.UIManager;
import java.awt.SystemColor;

public class PersonalImformationMaintenance extends JDialog {

	private JTextField tf1;
	private JTextField tf3;
	private JTextField tf2;
	private JRadioButton bt1;
	private JRadioButton bt2;
	private String radioText;//用于拿到单选框拿到的值
	private Controller controller;
	private JTextField tf4;
	private JLabel lb2;
	private JLabel lb4;
	public PersonalImformationMaintenance(Controller controller) {
		getContentPane().setBackground(Color.WHITE);
		this.controller = controller;
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 530, 555);
		getContentPane().setLayout(null);
		getContentPane().setForeground(Color.BLACK);
		getContentPane().setLayout(null);
		this.setLocationRelativeTo(null);//将窗口放在屏幕正中心
		this.getPanel();
		this.setVisible(true);
		this.validate();
		
	}
	public void getPanel() {
		JLabel lb1 = new JLabel("用户名:");
		lb1.setFont(new Font("华文楷体", Font.PLAIN, 20));
		lb1.setBounds(116, 53, 72, 27);
		getContentPane().add(lb1);
		
		tf1 = new JTextField();
		tf1.setFont(new Font("华文楷体", Font.PLAIN, 20));
		tf1.setColumns(10);
		tf1.setBounds(191, 174, 179, 31);
		getContentPane().add(tf1);
		
		JLabel lb3 = new JLabel("身份:");
		lb3.setFont(new Font("华文楷体", Font.PLAIN, 20));
		lb3.setBounds(133, 115, 72, 27);
		getContentPane().add(lb3);
		
		tf3 = new JTextField();
		tf3.setFont(new Font("华文楷体", Font.PLAIN, 20));
		tf3.setColumns(10);
		tf3.setBounds(191, 230, 179, 31);
		getContentPane().add(tf3);
		
		JLabel lb5 = new JLabel("密码:");
		lb5.setFont(new Font("华文楷体", Font.PLAIN, 20));
		lb5.setBounds(133, 176, 55, 27);
		getContentPane().add(lb5);
		
		lb2 = new JLabel("");
		lb2.setFont(new Font("华文楷体", Font.PLAIN, 20));
		lb2.setBounds(191, 53, 179, 27);
		getContentPane().add(lb2);
		
		lb4 = new JLabel("");
		lb4.setFont(new Font("华文楷体", Font.PLAIN, 20));
		lb4.setBounds(191, 115, 179, 27);
		getContentPane().add(lb4);
		
		JLabel lb7 = new JLabel("电话:");
		lb7.setFont(new Font("华文楷体", Font.PLAIN, 20));
		lb7.setBounds(133, 232, 55, 27);
		getContentPane().add(lb7);
		
		JLabel lb8 = new JLabel("性别:");
		lb8.setFont(new Font("华文楷体", Font.PLAIN, 20));
		lb8.setBounds(133, 348, 55, 27);
		getContentPane().add(lb8); 
		
		ButtonGroup group = new ButtonGroup();// 归组才能是实现单选
		bt1 = new JRadioButton("男");
		bt1.setBackground(Color.WHITE);
		bt1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (bt1.isSelected()) {
					radioText = bt1.getText(); 
				}
			}
		});
		bt1.setBounds(213, 344, 49, 35);
		bt1.setFont(new Font("华文楷体", Font.PLAIN, 20));
		group.add(bt1);
		getContentPane().add(bt1);

		bt2 = new JRadioButton("女");
		bt2.setBackground(Color.WHITE);
		bt2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (bt2.isSelected()) {
					radioText = bt2.getText();
				} 
			}
		});
		bt2.setBounds(299, 344, 49, 35);
		bt2.setFont(new Font("华文楷体", Font.PLAIN, 20));
		group.add(bt2);
		getContentPane().add(bt2);
		
		JButton bt3 = new JButton("提交");
		bt3.setIcon(new ImageIcon(PersonalImformationMaintenance.class.getResource("/logo/提交.png")));
		bt3.setForeground(Color.BLACK);
		bt3.setBackground(SystemColor.text);
		bt3.setFont(new Font("华文楷体", Font.PLAIN, 20));
		bt3.addActionListener(controller);
		bt3.setActionCommand("updateUserByOneself");
		bt3.setBounds(213, 427, 119, 35);
		getContentPane().add(bt3);
		
		JLabel lb9 = new JLabel("姓名:");
		lb9.setFont(new Font("华文楷体", Font.PLAIN, 20));
		lb9.setBounds(133, 290, 55, 27);
		getContentPane().add(lb9);
		
		tf4 = new JTextField();
		tf4.setFont(new Font("华文楷体", Font.PLAIN, 20));
		tf4.setColumns(10);
		tf4.setBounds(191, 288, 179, 31);
		getContentPane().add(tf4);
	}
	//通过性别信息 使得单选框被选中
	public void JudgeJRadioButton(String x) {
		if ("男".equals(x)) { // String类型不能用‘==’来判断是否相等，应该用equals()方法来判断
			bt1.setSelected(true);
			setRadioText(x);
		} else {
			bt2.setSelected(true);
			setRadioText("女");
		}
	} 
	public JTextField getTf1() {
		return tf1;
	}
	public void setTf1(JTextField tf1) {
		this.tf1 = tf1;
	}
	public JTextField getTf3() {
		return tf3;
	}
	public void setTf3(JTextField tf3) {
		this.tf3 = tf3;
	}
	public JTextField getTf2() {
		return tf2;
	}
	public void setTf2(JTextField tf2) {
		this.tf2 = tf2;
	}
	public String getRadioText() {
		return radioText;
	}
	public void setRadioText(String radioText) {
		this.radioText = radioText;
	}
	public JTextField getTf4() {
		return tf4;
	}
	public void setTf4(JTextField tf4) {
		this.tf4 = tf4;
	}
	public JLabel getLb2() {
		return lb2;
	}
	public void setLb2(JLabel lb2) {
		this.lb2 = lb2;
	}
	public JLabel getLb4() {
		return lb4;
	}
	public void setLb4(JLabel lb4) {
		this.lb4 = lb4;
	}
	
}
